<?php
class Zendhlt_Encode{

	public static function password($value, $options = null) {
		$newPass = md5($value);
		return $newPass;
	}

	public static function currency($value, $options = null) {
		$currency = new Zend_Currency(
		array(
                           "value"			=> $value,                           
                           "currency"		=> "VND",
                           "symbol"			=> "VNĐ",
                           "display"		=> 2,
                           "precision"		=> 0,
                           "number_format" 	=> "#.##0.00",
                           "locale"			=> "vi_VN",
                           "position"		=> Zend_Currency::RIGHT)
		);
		return $currency->toCurrency();
	}

	public static function truncateString_($str, $len, $charset="UTF-8") {
		$str = html_entity_decode($str, ENT_QUOTES, $charset);
		if(mb_strlen($str, $charset) > $len) {
			$arr = explode(' ', $str);
			$str = mb_substr($str, 0, $len, $charset);
			$arrRes = explode(' ', $str);
			$last = $arr[count($arrRes)-1];
			unset($arr);
			if(strcasecmp($arrRes[count($arrRes)-1], $last))   unset($arrRes[count($arrRes)-1]);
			return implode(' ', $arrRes)."...";
		}
		return $str;
	}
	
	public static function genRandomString($length = 10) {
		$characters = '0123456789abcdefghijklmnopqrstuvwxyz.ABCDEFGHIJKLMNOPQRSTUVWXYZ';
		$string = "";

		for ($p = 0; $p < $length; $p++) {
			$string .= $characters[mt_rand(0, strlen($characters)-1)];
		}

		return $string;
	}
}